<!-- 应急 》 应急物资 -->

<template>
  <CommonBody hasTree :tree="point_tree" :field="point_TREE_FIELD" initRoot diy @change="toChange">
    <!-- 结构树插槽 -->
    <template #treeBottom>
      <BtnAdd :word="point_MAP.WORD" mutation="point/add/openAdd" />
    </template>

    <!-- 物资点卡片 -->
    <EasyCard title="物资点信息">
      <PointEdit />
    </EasyCard>

    <!-- 物资卡片 -->
    <EasyCard title="物资列表" height="calc(100% - 238px)">
      <MySearch />
      <MyTable />
    </EasyCard>

    <!-- 物资弹窗 -->
    <MyModal />

    <!-- 物资点删除弹窗 -->
    <WebModal path="point" />

    <!-- 物资点新增弹窗 -->
    <WebModal path="point/add" small>
      <PointAdd />
    </WebModal>
  </CommonBody>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import store from './store'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'EmergencySupply',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixStore(store)],

  /**
   * 组件导入 (Abc.vue + Abc/index.vue)
   */
  ...CORE.components(require.context('./', true, /vue$/)),

  /**
   * 监听属性 (深度 deep 首次 immediate)
   */
  watch: {
    /**
     * 监听结构点列表就绪
     */
    point_readyList(ready) {
      if (ready) {
        this.point_setTree(this.point_list)
        const { point_one, point_tree, point_treeMap } = this
        const chosen = point_one.id ? point_treeMap[point_one.id] : point_tree[0] || {}
        this.toChange(chosen)
      }
    },
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 方法
     */
    toChange(data) {
      this.point_setOne(data)

      Object.assign(this.INIT_ONE, { pointId: data.id, pointName: data.name })

      this.param.pointId = data.id
      this.startList(1)
    },
  },
}
</script>
